package day1;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * @author oldliu
 * @since 1.0
 */
public class MapTest2 {
    public static void main(String[] args) {
        //遍历方法1
        Map<String, String> dict = new HashMap<>();
        //键值对
        //键不重复，不保证顺序
        //put,get,remove
        dict.put("狗", "dog");
        dict.put("猫", "cat");
        dict.put("蛇", "snake");
        dict.put("羊", "sheep");
        dict.put("羊", "goat");
        dict.put("龙", null);
        dict.put(null, "空");
        //1:获得所有的key的set;遍历set,找到key,找到value
        //dict.values();//value集合
        Set<String> set = dict.keySet();
        Iterator<String> ir = set.iterator();
        while (ir.hasNext()){
            String key=ir.next();
            String value=dict.get(key);
            System.out.println(key+"="+value);
        }
        System.out.println("遍历方法2----enforced for :");
        Set<Map.Entry<String, String>> entries = dict.entrySet();
        for(Map.Entry<String, String> o:entries){
            System.out.println(o.getKey()+"->"+o.getValue());
        }
    }
}
